package com.ren.mianshi.http2.callback;


import android.widget.Toast;

import com.ren.mianshi.App;
import com.ren.mianshi.constant.HttpConstant;
import com.ren.mianshi.http.RHttpCallback;
import com.ren.mianshi.http2.entity.CommonResponse;

import retrofit2.Call;
import retrofit2.Response;

/**
 * 网络接口公共业务处理层
 * TODO
 */

public abstract class CommonCallback<T extends CommonResponse> extends RHttpCallback<T> {


    @Override
    public void onProcess(Call<T> call, Response<T> response) {
        T t = response.body();
        if (t.code == HttpConstant.RESULT_OK) {
            onSuccess(call, t);
        } else {
            if (t.code == HttpConstant.HTTP_CODE_SESSION_FAIL_INT) {

            } else {
                onFail(call, t.code, t.msg);
            }
            onExtra(t);
        }
    }


    @Override
    public void onFail(Call<T> call, int state, String desc) {
        Toast.makeText(App.getInstance(),desc,Toast.LENGTH_SHORT);
    }

    public void onExtra(T t) {

    }

    @Override
    public void onComplete() {

    }


}
